package com.hmyd.hmyd_android.ui;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;

import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.DatePicker;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TableLayout;
import android.widget.TextView;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.hmyd.hmyd_android.R;
import com.hmyd.hmyd_android.AppBasic;
import com.hmyd.hmyd_android.adapter.FinancingDetailsListAdapter;
import com.hmyd.hmyd_android.commons.UrlConstant;
import com.hmyd.hmyd_android.dto.CapitalFlows;
import com.hmyd.hmyd_android.dto.FlowSummary;
import com.hmyd.hmyd_android.dto.Page;
import com.hmyd.hmyd_android.dto.Tag;
import com.hmyd.hmyd_android.utils.Utils;
import com.hmyd.hmyd_android.view.MySlidingDrawer;
import com.hmyd.hmyd_android.view.TagCloudLinkView;
import com.hmyd.hmyd_android.view.listview.XListView;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.lidroid.xutils.view.annotation.ContentView;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;

/**
 * 资金明细列表
 * @author Administrator
 */
@ContentView(R.layout.activity_financin_details)
public class FinancingDetailsListActivity extends BasicListActivity implements OnCheckedChangeListener {
	private static final int REFRESH = 1;
	private static final int LOADMORE = 2;
	private static final int FLOWSUMMARY = 3;
	
	@ViewInject(R.id.home_title)
	public View home_title;
	@ViewInject(R.id.home_title_txt)
	public TextView home_title_txt;
	@ViewInject(R.id.home_right)
	public TextView home_right;
	
	@ViewInject(R.id.list)
	private XListView mList;
	
	private FinancingDetailsListAdapter adapter;
	
	private List<CapitalFlows> listData = new ArrayList<CapitalFlows>();	// 数据列表
	
	private String cursorId;	// 翻页游标
	private boolean hasMore;	// 是否加载更多
	
	
	private HashMap<String,String> mTagsMap = new HashMap<String,String>();
	private ArrayList<Tag> mDefaultTags = new ArrayList<Tag>();
	
	@ViewInject(R.id.filter_layout)
	private View mFilterLayout;
	
	@ViewInject(R.id.check_deposit)
	private CheckBox mCheckDeposit;
	@ViewInject(R.id.check_currency)
	private CheckBox mCheckCurrency;
	@ViewInject(R.id.check_recommend)
	private CheckBox mCheckRecommend;
	@ViewInject(R.id.check_back)
	private CheckBox mCheckBack;
	@ViewInject(R.id.check_deductcoupon)
	private CheckBox mCheckDeductcoupon;
	@ViewInject(R.id.check_deduct)
	private CheckBox mCheckDeduct;
	@ViewInject(R.id.check_withdraw)
	private CheckBox mCheckWithdraw;
	
	@ViewInject(R.id.filter_start_time)
	private TextView mFilterStartTime;
	@ViewInject(R.id.filter_end_time)
	private TextView mFilterEndTime;
	
	int year = 0, monthOfYear = 0, dayOfMonth = 0;
	
	@ViewInject(R.id.summary_layout)
	private TableLayout mSummaryLayout;
	@ViewInject(R.id.summary_time)
	private TextView mSummaryTime;
	
//	private boolean isFirstInAssetDetail = true;
//	private FrameLayout mFrameLayout;
//	private Button mBtn;
	
	@ViewInject(R.id.slidingdrawer)
	private MySlidingDrawer mySlidingDrawer;
	@ViewInject(R.id.tags)
	private TagCloudLinkView mTags;
	
	@Override
	public XListView getXList() {
		return mList;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		
		onRequest(REFRESH, UrlConstant.CAPITALFLOWS, HttpMethod.GET, getTagsParams());
		onRequest(FLOWSUMMARY, UrlConstant.FLOWSUMMARY, HttpMethod.GET, getTagsParams());
	}
	
	@Override
	public void onRefresh() {
		super.onRefresh();
		
		RequestParams params = getTagsParams();
		
		onRequest(REFRESH, UrlConstant.CAPITALFLOWS, HttpMethod.GET, params);
		onRequest(FLOWSUMMARY, UrlConstant.FLOWSUMMARY, HttpMethod.GET, params);
	}
	
	@Override
	public void onLoadMore() {
		super.onLoadMore();
		
		RequestParams params = getTagsParams();
		params.addBodyParameter("lastCursor", cursorId);
		
		onRequest(LOADMORE, UrlConstant.CAPITALFLOWS, HttpMethod.GET, params);
	}
	
	/**
	 * 获取过滤条件
	 * @return 
	 */
	private RequestParams getTagsParams(){
		RequestParams params = new RequestParams();

		List<Tag> tags = null;

		if(mTags!=null){
			tags = mTags.getTags();
		}

		if(tags!=null && tags.size()>0){
			for(Tag tag:tags){
				if(tag.getId().equals("time")){
					SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

					if(!TextUtils.isEmpty(mFilterStartTime.getText())){
						System.out.println(mFilterStartTime.getText()+" 00:00:00");
						try {
							long millionSeconds = sdf.parse(mFilterStartTime.getText()+" 00:00:00").getTime();
							params.addBodyParameter("startTime", String.valueOf(millionSeconds));
						} catch (ParseException e) {
							e.printStackTrace();
						}//毫秒
					}

					if(!TextUtils.isEmpty(mFilterEndTime.getText())){
						System.out.println(mFilterEndTime.getText()+" 23:59:59");
						try {
							long millionSeconds = sdf.parse(mFilterEndTime.getText()+" 23:59:59").getTime();
							params.addBodyParameter("endTime", String.valueOf(millionSeconds));
						} catch (ParseException e) {
							e.printStackTrace();
						}//毫秒
					}

				}else{
					params.addBodyParameter("items", tag.getId());
				}
			}
		}

		return params;
	}
	
	@Override
	public void onPostSuccess(int postId, String msg) {
		super.onPostSuccess(postId, msg);
		
		Gson gson = new Gson();
		java.lang.reflect.Type type2 = new TypeToken<Page<CapitalFlows>>() {}.getType();
		Page<CapitalFlows> page = gson.fromJson(msg, type2);
		hasMore = page.hasMore;
		
		if(page!=null && page.records!=null){
			switch (postId) {
			case REFRESH:
				listData.clear();
				listData.addAll(page.records);
				break;
			case LOADMORE:
				listData.addAll(page.records);
				break;
			default:
				break;
			}
			
			if(listData.size()>0){
				cursorId = listData.get(listData.size()-1).cursorId;
			}else{
				cursorId = null;
			}
			
			adapter.notifyDataSetChanged();
		}
		
		if(getXList()!=null && hasMore){
			getXList().setPullLoadEnable(true);
		}else if(getXList()!=null && !hasMore){
			getXList().setPullLoadEnable(false);
		}
		
		if(postId==FLOWSUMMARY){//总计汇总
			Gson g = new Gson();
			java.lang.reflect.Type flowType = new TypeToken<FlowSummary>() {}.getType();
			FlowSummary flowSummary = g.fromJson(msg, flowType);
			
			stepFlowSummary(flowSummary);
			
		}
	}

	@Override
	public void onPostFailure(int postId, String msg) {
		super.onPostFailure(postId, msg);
		
		if(getXList()!=null && hasMore){
			getXList().setPullLoadEnable(true);
		}else if(getXList()!=null && !hasMore){
			getXList().setPullLoadEnable(false);
		}
	}
	
	/**
	 * 设置底部总计汇总数据
	 * @param flowSummary
	 */
	private void stepFlowSummary(FlowSummary flowSummary){
		if(flowSummary==null){
			return;
		}
		
		mSummaryLayout.removeAllViews();
		
		if(flowSummary.deposit!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("充值总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.deposit)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.currency!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("存钱罐收益总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.currency)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.recommend!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("好友推荐总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.recommend)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.back_interest!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("投资利息回款总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.back_interest)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.back_coupon!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("投资现金券回款总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.back_coupon)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.back_captial!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("投资本金回款总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.back_captial)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.deductcoupon!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("现金券抵扣总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.deductcoupon)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.deduct!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("投标扣款总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.deduct)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.withdraw!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("提现总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.withdraw)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.poundage!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("提现手续费总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.poundage)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.management!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("提现管理费总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.management)+"元");
			
			mSummaryLayout.addView(view);
		}
		
		if(flowSummary.refundticket!=0){
			LayoutInflater mInflater = LayoutInflater.from(this);
			View view = mInflater.inflate(R.layout.view_summary_item, null);
			TextView descTx = (TextView)view.findViewById(R.id.desc);
			TextView amountTx = (TextView)view.findViewById(R.id.amount);
			
			descTx.setText("提现失败（退票）总额：");
			amountTx.setText(Utils.amountConversionFormat(flowSummary.refundticket)+"元");
			
			mSummaryLayout.addView(view);
		}
	}

	/**
	 * 开始时间
	 * @param v
	 */
	@OnClick(R.id.filter_start_time)
	public void onFilterStartTimeClick(View v){
		DatePickerDialog startDatePickerDialog = new DatePickerDialog(this,AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            	
            	List<Tag> tags = null;
				if(mTags!=null){
					tags = mTags.getTags();
				}
				
				if(tags!=null && tags.size()>0){
					for(int i=0;i<tags.size();i++){
						Tag tag = tags.get(i);
						if(tag.getId().equals("time")){
							mTags.remove(i);
						}
					}
				}
            	
            	if(TextUtils.isEmpty(mFilterEndTime.getText())){
            		mTags.add(new Tag("time", year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 之后"));
            		mSummaryTime.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 之后");
            	}else{
            		mTags.add(new Tag("time", year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 至 " + mFilterEndTime.getText().toString()));
            		mSummaryTime.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 至 " + mFilterEndTime.getText().toString());
            	}
            	
            	mTags.drawTags();
            	
            	if(mTags.getTags().size()==0){
            		mTags.setVisibility(View.GONE);
            	}else{
            		mTags.setVisibility(View.VISIBLE);
            	}
            	
                mFilterStartTime.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }
        }, year, monthOfYear, dayOfMonth);
        
		startDatePickerDialog.show();
	}
	
	/**
	 * 结束时间
	 * @param v
	 */
	@OnClick(R.id.filter_end_time)
	private void onFilterEndTimeClick(View v){
		DatePickerDialog endDatePickerDialog = new DatePickerDialog(this,AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            	List<Tag> tags = null;
				if(mTags!=null){
					tags = mTags.getTags();
				}
				
				if(tags!=null && tags.size()>0){
					for(int i=0;i<tags.size();i++){
						Tag tag = tags.get(i);
						if(tag.getId().equals("time")){
							mTags.remove(i);
						}
					}
				}
            	
            	if(TextUtils.isEmpty(mFilterStartTime.getText())){
            		mTags.add(new Tag("time", year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 之前"));
            		mSummaryTime.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth + " 之前");
            	}else{
            		mTags.add(new Tag("time", mFilterStartTime.getText().toString() + " 至 " + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth));
            		mSummaryTime.setText(mFilterStartTime.getText().toString() + " 至 " + year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            	}
            	
            	mTags.drawTags();
            	
            	if(mTags.getTags().size()==0){
            		mTags.setVisibility(View.GONE);
            	}else{
            		mTags.setVisibility(View.VISIBLE);
            	}
            	
                mFilterEndTime.setText(year + "-" + (monthOfYear + 1) + "-" + dayOfMonth);
            }
        }, year, monthOfYear, dayOfMonth);
        
		endDatePickerDialog.show();
	}
	
	@Override
	protected void setParams() {
		home_title_txt.setText(getString(R.string.financing_details_list));
		home_title.setOnTouchListener(touch);
		home_right.setVisibility(View.VISIBLE);
		home_right.setText(getString(R.string.filter));
		
		mList.setPullRefreshEnable(true); // 允许下拉刷新
		mList.setPullLoadEnable(false); // 禁止加载更多
		mList.setAutoLoadEnable(false); // 禁止自动加载
		mList.setXListViewListener(this);// 加载监听
		
		adapter = new FinancingDetailsListAdapter(this, listData);
		
		mList.setAdapter(adapter);
		
		mTagsMap.put("deposit", "充值");
		mTagsMap.put("currency", "存钱罐收益");
		mTagsMap.put("recommend", "好友推荐");
		mTagsMap.put("back", "投资回款");
		mTagsMap.put("deductcoupon", "现金券抵扣");
		mTagsMap.put("deduct", "投标扣款");
		mTagsMap.put("withdraw", "提现");
		
		if(getIntent().getBooleanExtra("init", false)){
			mDefaultTags.add(new Tag("currency","存钱罐收益"));
			mDefaultTags.add(new Tag("recommend", "好友推荐"));
			mDefaultTags.add(new Tag("back", "投资回款"));
		}
		
		year = Calendar.getInstance().get(Calendar.YEAR);
		monthOfYear = Calendar.getInstance().get(Calendar.MONTH);
		dayOfMonth = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
		
		
		if(mDefaultTags.size()==0){
			mTags.setVisibility(View.GONE);
		}else{
			mTags.setVisibility(View.VISIBLE);
		}
		
		for(Tag tag:mDefaultTags){
			mTags.add(tag);
		}
		mTags.drawTags();
		
		mTags.setOnTagDeleteListener(new TagCloudLinkView.OnTagDeleteListener(){
		    @Override
		    public void onTagDeleted(Tag tag, int i) {
		    	
		    	if(mFilterLayout.getVisibility()==View.GONE){//不是过滤的时候
		    		adapter.notifyDataSetChanged();
			    	mList.setSelection(0);
			    	
			    	if(tag.getId().equals("time")){
						mFilterStartTime.setText("");
						mFilterEndTime.setText("");
					}
			    	
			    	RequestParams params = getTagsParams();
			    	
			    	onRequest(REFRESH, UrlConstant.CAPITALFLOWS, HttpMethod.GET, params);
		    	}else{
		    		if(tag.getId().equals("deposit")){
						mCheckDeposit.setChecked(false);
					}else if(tag.getId().equals("currency")){
						mCheckCurrency.setChecked(false);
					}else if(tag.getId().equals("recommend")){
						mCheckRecommend.setChecked(false);
					}else if(tag.getId().equals("back")){
						mCheckBack.setChecked(false);
					}else if(tag.getId().equals("deductcoupon")){
						mCheckDeductcoupon.setChecked(false);
					}else if(tag.getId().equals("deduct")){
						mCheckDeduct.setChecked(false);
					}else if(tag.getId().equals("withdraw")){
						mCheckWithdraw.setChecked(false);
					}else if(tag.getId().equals("time")){
						mFilterStartTime.setText("");
						mFilterEndTime.setText("");
					}
		    		
		    	}
		    	
		    	if(mTags.getTags().size()==0){
		    		mTags.setVisibility(View.GONE);
		    	}else{
		    		mTags.setVisibility(View.VISIBLE);
		    	}
		    }
		});
	}

	@Override
	protected void leftButton() {
		AppBasic.getInstance().finishCurrentActivity();
	}

	/**
	 * 过滤事件
	 */
	@Override
	protected void rightButton() {
		if(home_right.getText().toString().equals(getResources().getString(R.string.filter))){ //展示过滤
			home_right.setText(R.string.quit);
			mFilterLayout.setVisibility(View.VISIBLE);
			
			List<Tag> tags = null;
			if(mTags!=null){
				tags = mTags.getTags();
			}
			
			if(tags!=null && tags.size()>0){
				for(int i=0;i<tags.size();i++){
					Tag tag = tags.get(i);
					if(tag.getId().equals("deposit")){
						mCheckDeposit.setChecked(true);
					}else if(tag.getId().equals("currency")){
						mCheckCurrency.setChecked(true);
					}else if(tag.getId().equals("recommend")){
						mCheckRecommend.setChecked(true);
					}else if(tag.getId().equals("back")){
						mCheckBack.setChecked(true);
					}else if(tag.getId().equals("deductcoupon")){
						mCheckDeductcoupon.setChecked(true);
					}else if(tag.getId().equals("deduct")){
						mCheckDeduct.setChecked(true);
					}else if(tag.getId().equals("withdraw")){
						mCheckWithdraw.setChecked(true);
					}
					
				}
			}
			
			mCheckDeposit.setOnCheckedChangeListener(this);
			mCheckCurrency.setOnCheckedChangeListener(this);
			mCheckRecommend.setOnCheckedChangeListener(this);
			mCheckBack.setOnCheckedChangeListener(this);
			mCheckDeductcoupon.setOnCheckedChangeListener(this);
			mCheckDeduct.setOnCheckedChangeListener(this);
			mCheckWithdraw.setOnCheckedChangeListener(this);
			
		}else{ //开始过滤
			home_right.setText(R.string.filter);
			mFilterLayout.setVisibility(View.GONE);
			
			mCheckDeposit.setOnCheckedChangeListener(null);
			mCheckCurrency.setOnCheckedChangeListener(null);
			mCheckRecommend.setOnCheckedChangeListener(null);
			mCheckBack.setOnCheckedChangeListener(null);
			mCheckDeductcoupon.setOnCheckedChangeListener(null);
			mCheckDeduct.setOnCheckedChangeListener(null);
			mCheckWithdraw.setOnCheckedChangeListener(null);
			
			mCheckDeposit.setChecked(false);
			mCheckCurrency.setChecked(false);
			mCheckRecommend.setChecked(false);
			mCheckBack.setChecked(false);
			mCheckDeductcoupon.setChecked(false);
			mCheckDeduct.setChecked(false);
			mCheckWithdraw.setChecked(false);
			
			adapter.notifyDataSetChanged();
	    	mList.setSelection(0);
	    	
	    	RequestParams params = getTagsParams();
	    	
	    	onRequest(REFRESH, UrlConstant.CAPITALFLOWS, HttpMethod.GET, params);
	    	onRequest(FLOWSUMMARY, UrlConstant.FLOWSUMMARY, HttpMethod.GET, params);
		}
	}

	/**
	 * 多选
	 */
	@Override
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if(isChecked){
			switch (buttonView.getId()) {
				case R.id.check_deposit:
					mTags.add(new Tag("deposit", "充值"));
					
					mTags.drawTags();
					break;
				
				case R.id.check_currency:
					mTags.add(new Tag("currency", "存钱罐收益"));
					
					mTags.drawTags();
					break;
					
				case R.id.check_recommend:
					mTags.add(new Tag("recommend", "好友推荐"));
					
					mTags.drawTags();
					break;
					
				case R.id.check_back:
					mTags.add(new Tag("back", "投资回款"));
					
					mTags.drawTags();
					break;
					
				case R.id.check_deductcoupon:
					mTags.add(new Tag("deductcoupon", "现金券抵扣"));
					
					mTags.drawTags();
					break;
					
				case R.id.check_deduct:
					mTags.add(new Tag("deduct", "投标扣款"));
					
					mTags.drawTags();
					break;
					
				case R.id.check_withdraw:
					mTags.add(new Tag("withdraw", "提现"));
					
					mTags.drawTags();
					break;
			default:
				break;
			}
		}else{
			List<Tag> tags = null;
			if(mTags!=null){
				tags = mTags.getTags();
			}
			
			if(tags!=null && tags.size()>0){
				for(int i=0;i<tags.size();i++){
					Tag tag = tags.get(i);
					
					if(buttonView.getText().toString().equals(tag.getText())){
						mTags.remove(i);
						
						break;
					}
				}
			}
		}
		
		if(mTags.getTags().size()==0){
    		mTags.setVisibility(View.GONE);
    	}else{
    		mTags.setVisibility(View.VISIBLE);
    	}
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		
		if (listData.size() >0) {
			listData.clear();
			listData = null;
		}
		
		if (mTags != null) {
			mTags.removeAllViews();
		}
		
		if (mTagsMap.size() > 0) {
			mTagsMap.clear();
			mTagsMap = null;
		}
		
		if (mDefaultTags.size() > 0) {
			mDefaultTags.clear();
			mDefaultTags = null;
		}
	}

}
